﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dictionary.Core
{
    public class GetData
    {
        public String strUrl { get; set; }
        public GetData()
        { }
        public GetData(String strUrl)
        {
            this.strUrl = strUrl;
        }

        public void Save()
        {
            // to get all category
            List<Category> allCategory = new List<Category>();
            Crawler crawler = new Crawler(strUrl);
            List<Category> listSource = crawler.getSource();
            foreach (Category itemSource in listSource)
            {
                crawler = new Crawler(itemSource.link);
                List<Category> listCategory = crawler.getCategory();
                allCategory.AddRange(listCategory);
            }
            // to save to database
            Category.insertAll(allCategory, 1);

            // to get all category from database
            allCategory = Category.selectAll(1);
            foreach (Category itemCategory in allCategory)
            {
                // to save vocab to database
                crawler = new Crawler(itemCategory.link);
                List<Vocabulary> listVocab = crawler.getVocabulary();
                Vocabulary.insertAll(listVocab, itemCategory.id);
            }
        }
    }
}
